package com.gaff.emp.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gaff.emp.core.EmpException;
import com.gaff.emp.core.R;
import com.gaff.emp.core.modules.auth.annotation.Auth;
import com.gaff.emp.data.Data;
import com.gaff.emp.data.DerverListData;
import com.gaff.emp.data.Hospital;
import com.gaff.emp.data.Hospital;
//import com.sun.org.apache.xml.internal.security.Init;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.UUID;


@Slf4j
@RestController
public class DemoController1 {

    @GetMapping("/zhl/demo")
//    @Auth
    public R demo()  {
       return R.ok("ok");
    }

    @GetMapping("/zhl/test")
    public R test() {
        JSONObject json = new JSONObject();
        JSONArray arr = new JSONArray();
        arr.add("数组中的字符串");
        JSONObject obj = new JSONObject();
        for (int i=0;i<10;i++){
            obj = new JSONObject();
            obj.put("name","name"+i);
            arr.add(obj);
        }

        json.put("id",123);
        json.put("id",123);
        json.put("list",arr);

        return R.ok(json);
    }


    @GetMapping("/zhl/demog")
    public R demo2(String id,int age)  {
        System.out.println(id);
        System.out.println(age);

        if(age==0){
            throw new EmpException("age不能是0");
        }
        System.out.println(10/age);

        return R.ok("get id="+id+",age="+age);
    }
    @PostMapping("/zhl/demop")
    public R demo3(Map<String,Object> map)  {
        System.out.println(map);
        String username = (String)map.get("username");
        String pwd = (String)map.get("pwd");
        System.out.println(username);
        System.out.println(pwd);
        return R.ok(map);
    }

    @GetMapping("/zhl/page1")
    public R demo2(int page,int limit)  {
        System.out.println(page);
        System.out.println(limit);


        return R.ok(Data.list);
    }

    @GetMapping("/userinfo")
    @Auth
    public R demo6()  {
        JSONObject json = new JSONObject();

        json.put("id", UUID.randomUUID().toString());
        json.put("brxm","张超杰");
        json.put("csrq","1988-10-05");
        json.put("lxrdhhm","15875465987");
        json.put("xbdm","男");
        json.put("abo","a");
        json.put("jdryxm","张超杰");
        json.put("hyzklbdm","已婚");
        json.put("jdsj","2021-09-18");
        json.put("xzdz","湖南省长沙市长沙县金茂路3号");
        json.put("cxjmjkdabh","1785468145");
        json.put("ywgmy",null);
        json.put("hjwxysbllbdm",null);
        json.put("jzjbs","父亲乙肝");
        json.put("ycxjbs","父亲乙肝");


        return R.ok(json);
    }
    @GetMapping("/server/list")
    @Auth
    public R demo7(int page,int limit)  {
        if(page==0){
            throw new EmpException("页数从1开始");
        }
        int size = DerverListData.list.size();
        int num1 = (page-1)*limit;
        int max = (page*limit-1)>=size?size-1:(page*limit-1);
        JSONObject json = new JSONObject();
        json.put("currentPage",page);
        json.put("totalCount", DerverListData.list.size());
        json.put("pageSize", limit);
        JSONArray arr = new JSONArray();
        for (int i = num1; i <= max; i++) {
            arr.add(DerverListData.list.get(i));
        }
        json.put("list", arr);
        return R.ok(json);
    }
    @GetMapping("/hosptial/menuList")
    @Auth
    public R demo7()  {
        JSONArray arr = new JSONArray();
        JSONObject obj ;

        int size = Hospital.menuList.size();
        for (int i = 0; i < size; i++) {
            obj = new JSONObject();
            Map map = (Map)Hospital.menuList.get(i);
            obj.put("id",map.get("id"));
            obj.put("recordDate",map.get("recordDate"));
            obj.put("lsh", map.get("lsh"));
            obj.put("yljgmc",map.get("yljgmc"));

            arr.add(obj);
        }

        return R.ok(arr);
    }
    @GetMapping("/hosptial/menuList/detail")
    @Auth
    public R demo8(String id)  {
        ArrayList arr = null;

        int size = Hospital.menuList.size();
        for (int i = 0; i < size; i++) {
            Map map = (Map)Hospital.menuList.get(i);
            String newID = (String) map.get("id");
            System.out.println("mapid----"+newID);
            System.out.println("idddd----"+id);
            System.out.println("布尔值----"+id==newID);
            System.out.println("equal----"+id.equals(newID));
            if(id.equals(newID)){
                System.out.println("进入了");
                System.out.println(map);
                arr = (ArrayList) map.get("dateList");
            }

        }

        return R.ok(arr);
    }
}
